'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
	const collection = db.collection('uni-id-users')
	
	
	let {data} = await collection.where({
	  openid:event.openid
	}).limit(1).get()
	
	
	if(data.length>0){
		
		let id=event.data[0]._id
		const res = await collection.doc(id).update(event);		
	}else{
		const res = await collection.add(event)
	}
	return res
};